meta %>%
filter(su_tract == 1) %>%
select(varname, about) %>% as.list()
## $varname
## [1] "tract" "county" "avgc_alltr"
## [4] "medc_alltr" "commutersIntr" "avgc_within40tr"
## [7] "medc_within40tr" "commuterw40tr" "avgc_25_employeestr"
## [10] "medc_25_employeestr" "commuter25tr" "avgc_workinRegiontr"
## [13] "medc_workinRegiontr" "commuterinRegiontr"
##
## $about
## [1] "11-digit census tract code"
## [2] "5-digit county code"
## [3] "Average \"as the crow flies\" commuting distance for all residents in the census tract"
## [4] "Median \"as the crow flies\" commuting distance for all residents in the census tract"
## [5] "The number of residents in each census tract who are represented in the data"
## [6] "Average \"as the crow flies\" commuting distance for residents of the census tract who work within 40 miles"
## [7] "Median \"as the crow flies\" commuting distance for residents of the census tract who work within 40 miles"
## [8] "The number of residents in the census tract who work within 40 miles of home"
## [9] "Average \"as the crow flies\" commuting distance for residents of the census tract who commute to a census tract that employs at least 25 residents from the region of interest"
## [10] "Median \"as the crow flies\" commuting distance for residents of the census tract who commute to a census tract that employs at least 25 residents of the region of interest"
## [11] "The number of residents in the census tract who commute to a census tract that employs at least 25 residents of the region of interest"
## [12] "Average \"as the crow flies\" commuting distance for residents of the census tract who work in the same region as where they live"
## [13] "Median \"as the crow flies\" commuting distance for residents of the census tract who work in the same region as where they live"
## [14] "The number of residents living in the census tract who commute to work within the region of interest"
glimpse(lodes)
## Rows: 50
## Columns: 14
## $ tract <dbl> 51003010100, 51003010201, 51003010202, 51003010300…
## $ medc_alltr <dbl> 27.97247, 20.30768, 18.34769, 19.20226, 24.75778, …
## $ medc_workinRegiontr <dbl> 7.568706, 4.736960, 2.938385, 4.120100, 9.673803, …
## $ medc_within40tr <dbl> 9.373904, 6.713784, 4.345703, 5.958594, 11.009505,…
## $ medc_25_employeestr <dbl> 20.59655, 13.97487, 13.88836, 13.94813, 19.50496, …
## $ commutersIntr <int> 2124, 2387, 1477, 3875, 1890, 1397, 2436, 2625, 17…
## $ commuterinRegiontr <int> 1460, 1795, 1133, 2937, 1320, 1020, 1897, 1905, 13…
## $ commuterw40tr <int> 1629, 1967, 1208, 3202, 1491, 1116, 2057, 2103, 15…
## $ commuter25tr <int> 1948, 2240, 1389, 3646, 1749, 1304, 2312, 2446, 16…
## $ avgc_alltr <dbl> 29.49535, 20.02431, 19.23946, 19.34351, 25.56457, …
## $ avgc_workinRegiontr <dbl> 8.138391, 4.976508, 3.208846, 4.316983, 10.119677,…
## $ avgc_within40tr <dbl> 9.722919, 6.784946, 4.543631, 6.040549, 11.349601,…
## $ avgc_25_employeestr <dbl> 22.85983, 15.48127, 15.25275, 14.75717, 20.70080, …
## $ county <int> 51003, 51003, 51003, 51003, 51003, 51003, 51003, 5…
lodes %>% select(avgc_alltr, avgc_within40tr, avgc_25_employeestr, avgc_workinRegiontr, medc_alltr, medc_within40tr, medc_25_employeestr, medc_workinRegiontr) %>%
select(where(~is.numeric(.x))) %>%
as.data.frame() %>%
stargazer(., type = "text", title = "Summary Statistics", digits = 2,
summary.stat = c("mean", "sd", "min", "median", "max"))
##
## Summary Statistics
## =====================================================
## Statistic Mean St. Dev. Min Median Max
## -----------------------------------------------------
## avgc_alltr 25.85 9.82 15.36 24.12 76.12
## avgc_within40tr 9.00 5.09 3.36 7.52 20.58
## avgc_25_employeestr 20.26 8.58 10.53 18.50 64.77
## avgc_workinRegiontr 7.39 5.77 1.52 5.04 19.82
## medc_alltr 25.60 10.18 14.15 24.06 78.38
## medc_within40tr 8.88 5.06 3.21 6.94 20.32
## medc_25_employeestr 19.81 8.72 9.78 18.35 64.84
## medc_workinRegiontr 7.15 5.64 1.37 4.76 18.63
## -----------------------------------------------------
long <- lodes %>% select(c(tract, avgc_alltr, avgc_within40tr, avgc_25_employeestr, avgc_workinRegiontr, medc_alltr, medc_within40tr, medc_25_employeestr, medc_workinRegiontr)) %>%
pivot_longer(-tract, names_to = "measure", values_to = "value")
long$measure <- factor(long$measure,
levels = c("avgc_alltr", "medc_alltr", "avgc_within40tr", "medc_within40tr", "avgc_25_employeestr", "medc_25_employeestr", "avgc_workinRegiontr",
"medc_workinRegiontr"))
long %>%
ggplot(aes(x = value, fill = measure)) +
scale_fill_viridis(option = "plasma", discrete = TRUE, guide = FALSE) +
geom_histogram() +
facet_wrap(~measure, scales = "free", ncol = 2)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
meta %>%
filter(varname %in% c("avgc_alltr", "avgc_within40tr", "avgc_25_employeestr", "avgc_workinRegiontr")) %>%
mutate(label = paste0(varname, ": ", about)) %>%
select(label) %>%
as.list()
$label [1] "avgc_alltr: Average "as the crow flies" commuting distance for all residents in the census tract"
[2] "avgc_within40tr: Average "as the crow flies" commuting distance for residents of the census tract who work within 40 miles"
[3] "avgc_25_employeestr: Average "as the crow flies" commuting distance for residents of the census tract who commute to a census tract that employs at least 25 residents from the region of interest" [4] "avgc_workinRegiontr: Average "as the crow flies" commuting distance for residents of the census tract who work in the same region as where they live"
pal <- colorNumeric("plasma", reverse = T, domain = cvl_lodes$avgc_alltr)
leaflet(cvl_lodes) %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data = cvl_lodes,
fillColor = ~pal(avgc_alltr),
weight = 1,
opacity = 1,
color = "white",
fillOpacity = 0.6,
highlight = highlightOptions(
weight = 1, fillOpacity = 0.8, bringToFront = T
),
popup = paste0("GEOID: ", cvl_lodes$tract, "<br>",
"Average commute (mi): ", round(cvl_lodes$avgc_alltr, 2))) %>%
addLegend("bottomright", pal = pal, values = cvl_lodes$avgc_alltr,
title = "Average commute (mi)", opacity = 0.7)
meta %>%
filter(varname %in% c("avgc_alltr")) %>%
mutate(label = paste0(varname, ": ", about)) %>%
select(label) %>%
as.list()
$label [1] "avgc_alltr: Average "as the crow flies" commuting distance for all residents in the census tract"
pal <- colorNumeric("plasma", reverse = T, domain = cvl_lodes$avgc_within40tr)
leaflet(cvl_lodes) %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data = cvl_lodes,
fillColor = ~pal(avgc_within40tr),
weight = 1,
opacity = 1,
color = "white",
fillOpacity = 0.6,
highlight = highlightOptions(
weight = 1, fillOpacity = 0.8, bringToFront = T
),
popup = paste0("GEOID: ", cvl_lodes$tract, "<br>",
"Average commute (mi): ", round(cvl_lodes$avgc_within40tr, 2))) %>%
addLegend("bottomright", pal = pal, values = cvl_lodes$avgc_within40tr,
title = "Average commute (mi)", opacity = 0.7)
meta %>%
filter(varname %in% c("avgc_within40tr")) %>%
mutate(label = paste0(varname, ": ", about)) %>%
select(label) %>%
as.list()
$label [1] "avgc_within40tr: Average "as the crow flies" commuting distance for residents of the census tract who work within 40 miles"
pal <- colorNumeric("plasma", reverse = T, domain = cvl_lodes$avgc_25_employeestr)
leaflet(cvl_lodes) %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data = cvl_lodes,
fillColor = ~pal(avgc_25_employeestr),
weight = 1,
opacity = 1,
color = "white",
fillOpacity = 0.6,
highlight = highlightOptions(
weight = 1, fillOpacity = 0.8, bringToFront = T
),
popup = paste0("GEOID: ", cvl_lodes$tract, "<br>",
"Average commute (mi): ", round(cvl_lodes$avgc_25_employeestr, 2))) %>%
addLegend("bottomright", pal = pal, values = cvl_lodes$avgc_25_employeestr,
title = "Average commute (mi)", opacity = 0.7)
meta %>%
filter(varname %in% c("avgc_25_employeestr")) %>%
mutate(label = paste0(varname, ": ", about)) %>%
select(label) %>%
as.list()
$label [1] "avgc_25_employeestr: Average "as the crow flies" commuting distance for residents of the census tract who commute to a census tract that employs at least 25 residents from the region of interest"
pal <- colorNumeric("plasma", reverse = T, domain = cvl_lodes$avgc_workinRegiontr)
leaflet(cvl_lodes) %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data = cvl_lodes,
fillColor = ~pal(avgc_workinRegiontr),
weight = 1,
opacity = 1,
color = "white",
fillOpacity = 0.6,
highlight = highlightOptions(
weight = 1, fillOpacity = 0.8, bringToFront = T
),
popup = paste0("GEOID: ", cvl_lodes$tract, "<br>",
"Average commute (mi): ", round(cvl_lodes$avgc_workinRegiontr, 2))) %>%
addLegend("bottomright", pal = pal, values = cvl_lodes$avgc_workinRegiontr,
title = "Average commute (mi)", opacity = 0.7)
meta %>%
filter(varname %in% c("avgc_workinRegiontr")) %>%
mutate(label = paste0(varname, ": ", about)) %>%
select(label) %>%
as.list()
$label [1] "avgc_workinRegiontr: Average "as the crow flies" commuting distance for residents of the census tract who work in the same region as where they live"